package com.zzhou.linkinfo.clock.util;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import java.text.SimpleDateFormat;

public class Utils {

    /**
     * 获取屏幕高度
     */
    public static int getWindowHeight(Context context) {
        WindowManager manager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        manager.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.heightPixels;
    }

    /**
     * 获取屏幕宽度
     */
    public static int getWindowWidth(Context context) {
        WindowManager manager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        manager.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.widthPixels;
    }

    public static String timeParse(long duration) {
        String time = "";
        String minuteStr = "";
        String secondStr = "";
        long minute = duration / 60000L;
        long seconds = duration % 60000L;
        long second = (long) Math.round((float) seconds / 1000.0F);

        if (minute > 0) {
            minuteStr = minute + "\'";
        }
        if (second > 0) {
            secondStr = second + "\"";
        }
        time = minuteStr + secondStr;

        return time;
    }

    public static String timeParseMinute(long duration) {
        SimpleDateFormat msFormat = new SimpleDateFormat("mm:ss");
        try {
            return msFormat.format(duration);
        } catch (Exception var3) {
            var3.printStackTrace();
            return "";
        }
    }

    public static int dp2px(Context context, float dpValue) {
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
